@extends('layout.default')

@section('layout.content')

<div class="row">
    <div class="col-xs-12 align-right">
      <div style="margin-bottom: 15px;">
        <a href="{{route('train.deploy.create')}}" class="btn btn-lg btn-success dialog"><i class="ace-icon fa fa-pencil-square-o"></i>新建培训发布方案</a>
      </div>
    </div>
  </div><!-- /.row -->

  <div class="row">
    <div class="col-xs-12">
      <table class="table table-hover table-striped table-bordered">
        <thead>
        <tr>
          <th class="align-middle" style="width:110px;">发布名称</th>
          <th class="align-middle" style="width:200px;">属性</th>
          <th class="center" style="width:50px;">报名限制</th>
          <th class="center">门类</th>
          <th class="center">班级</th>
          <th class="center" style="width:50px;">计划招生</th>
          <th class="center" style="width:50px;">已报名</th>
          <th class="center" style="width:50px;">额满限招</th>
          <th class="center" style="width:50px;">入学考试</th>
          <th class="center" style="width:50px;">上交作品</th>
          <th class="center" style="width:100px;">状态</th>
        </tr>
        </thead>
        <tbody>
          @foreach ($deploys as $deploy)
          <?php
            $termsCount = count($deploy->infos);
            if($termsCount <= 0) $termsCount = 1;
            $rowspan = $termsCount == 1 ? '' : "rowspan='{$termsCount}'";
            $info = $deploy->infos->shift();
          ?>
            <tr>
              <td class="deploy" {!! $rowspan !!}>
                <a href="{{route('train.deploy.edit',$deploy->id)}}">{{ $deploy->name }}</a>
              </td>
              <td class="" {!! $rowspan !!}>
                <p>类型：<b>{{ $deploy->term->type->name }}</b></p>
                <p>分支：<b>{{ $deploy->term->branch->name }}</b></p>
                <p>学期：<b>{{ $deploy->term->name }}</b></p>
              </td>
              <td class="align-top-center" {!! $rowspan !!}>{!! $deploy->present()->limitStatus() !!}</td>
              <td class="center" >{{ $info->clase->category->name }}</td>
              <td class="center" >{{ $info->clase->name }}</td>
              <td class="center" >{{ $info->clase->number }}</td>
              <td class="center" >{{ count($info->clase->users) }}</td>
              <td class="center" >{!! $info->clase->present()->isLimited() !!}</td>
              <td class="center" >{!! $info->clase->present()->isExam() !!}</td>
              <td class="center" >{!! $info->clase->present()->isHandin() !!}</td>
              <td class="align-top-center" {!! $rowspan !!}>
                 <div class="form-group">
                    <div class="btn-group">
                      <button data-toggle="dropdown" class="btn btn-primary btn-white dropdown-toggle">
                        {!! $deploy->present()->deployStatus() !!}
                        <i class="ace-icon fa fa-angle-down icon-on-right"></i>
                      </button>
                      <ul class="dropdown-menu dropdown-inverse dropdown-status">
                        <li>
                          <a href="javascript:;" class="inplan" data-id="{{$deploy->id}}" data-status="{{$deploy->status}}">
                            {!! $deploy->present()->inverseStatus() !!}
                          </a>
                        </li>
                      </ul>
                    </div>
                  </div>
              </td>
            </tr>
            @if($rowspan != '')
              @foreach($deploy->infos as $info)
              <tr>
                <td class="center" >{{ $info->clase->category->name }}</td>
                <td class="center" >{{ $info->clase->name }}</td>
                <td class="center" >{{ $info->clase->number }}</td>
                <td class="center" >{{ count($info->clase->users) }}</td>
                <td class="center" >{!! $info->clase->present()->isLimited() !!}</td>
                <td class="center" >{!! $info->clase->present()->isExam() !!}</td>
                <td class="center" >{!! $info->clase->present()->isHandin() !!}</td>
              </tr>
              @endforeach
            @endif

          @endforeach
        </tbody>
      </table>
    </div>

  </div>

@stop

@section('javascript')

  <script src="//cdn.bootcss.com/jquery-validate/1.19.1/jquery.validate.min.js"></script>
  <script src="{{URL::asset('assets/js/jquery-validate-methods.js')}}"></script>
  <script src="//cdn.bootcss.com/jqueryui/1.12.1/jquery-ui.min.js"></script>

  <script type="text/javascript">
    $(function () {

      $('.inplan').on('click', function () {

        var uri = "{{route('train.deploy.change')}}";

        var id = $(this).data('id');
        var status = $(this).data('status');

        $.post(uri, {
          '_token': $("input[name='_token']").attr('value'),
          'id': id,
          'status': status,
        }, function (data) {
          console.log(data);
          layer.msg(data.message, {time:1000,shift: -1}, function () {
              if (data.status === true && data.url != null) {
                  $(window).attr('location', data.url);
              }
          });

        }, 'json').error(function (data) {
          layer.msg(data.responseJSON.message);
        });

    });

    $('.deploy').on('mouseenter', function () {
        $(this).find('.operate').show();
    }).on('mouseleave', function () {
        $(this).find('.operate').hide();
    });

  });
</script>
@stop
